<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    <% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
        + request.getServerPort() + path + "/" ; %>
        <!DOCTYPE html>
        <html>

        <head>
            <base href="<%=basePath%>">
            <title>我的竞价</title>
            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
        </head>
        <style>
            .tdText {
                text-align: right;
                width: 400px;
                height: 20px;
            }
        </style>

        <body>
            <%@ include file="/WEB-INF/jsp/common/headerSupply.jsp" %>
                <%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

                    <script type="text/javascript">
                        $(function () {
                            $('#startTime').datebox('setValue', getBeforeCurrentDate30Days());
                            $('#endTime').datebox('setValue', getNowFormatDate());
                            bingGrid();

                            $("#uploadbtn").bind("click", function (e) {
                                $("#uploadpicker").click();
                            });
                        });

                    </script>

                    <div class="query_criteria" id="query_criteria">
                        <div style="margin: 5px 0px">
                            <%-- 搜索框 --%>
                                <label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
                                    name="startTime" id="startTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
                                    class="easyui-datebox" name="endTime" id="endTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    style="width: 150px" /> <label
                                    style="margin-left: 20px; font-size: 12px;">状态：</label> <input
                                    class="easyui-combobox" id="supplyOfferStatus" name="status" style="width: 80px;"
                                    data-options="valueField: 'value',editable:false,
		textField: 'label',panelHeight:'auto',data: [{
			label: '全部',
			value: ''
		},{
			label: '竞价中',
			value: '0',
			selected:true
		},{
			label: '已完成',
			value: '1'
		}]">
                                <a id="search" style="margin-left: 30px" href="javascript:void(0)"
                                    class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                                    onclick="selectList()">查询</a><input type="file" id="uploadMM" accept=""
                                    onchange="changeMM()" style="display: none;" />
                        </div>
                        <%--我的报价列表DataGrid --%>
                            <table id="dataGridDiv"></table>

                            <div id="recordWindow" class="easyui-window" closed="true" modal="true" title="报价记录"
                                style="width: 700px; height: 400px; padding: 5px 5px">
                                <table id="recordTT"></table>
                            </div>
                            <div id="recordMmWindow" class="easyui-window" closed="true" modal="true" title="报价明细"
                                style="width: 900px; height: 400px; padding: 5px 5px">
                                <table id="recordMmTT"></table>
                            </div>

                            <div id="rankWindow" class="easyui-window" closed="true" modal="true" title="排名信息"
                                style="width: 900px; height: 400px; padding: 5px 5px">
                                <div>
                                    <span id="spanRank"></span>
                                </div>
                                <table id="rankTT"></table>
                            </div>
                            <%-- 详情弹窗 --%>
                                <div id="supplyOfferWindow" class="easyui-window" closed="true" modal="true"
                                    title="供应商报价" style="width: 900px; height: 400px; padding: 5px 5px">
                                    <form id="supplyOfferForm">
                                        <div class="easyui-tabs" id="tabs" style="width: 875px; height: 350px">
                                            <div title="基本信息">
                                                <table>
                                                    <tr style="margin-bottom: 10px">
                                                        <td colspan="1" class="tdText"><input id="infId" type="hidden"
                                                                class="easyui-validatebox textbox" style="width: 60%">
                                                            <label style="width: 40%; text-align: right;">询价名称：</label>
                                                            <input id="inqName" class="easyui-validatebox textbox"
                                                                style="width: 60%"> <input id="inqId" type="hidden"
                                                                class="easyui-validatebox textbox" style="width: 60%">
                                                        </td>
                                                        <td colspan="1" class="tdText"><label
                                                                style="width: 40%; text-align: right;">联系人：</label>
                                                            <input id="infContact" class="easyui-validatebox textbox"
                                                                style="width: 60%" data-options="required:true">
                                                        </td>
                                                        <td colspan="1" class="tdText"><label
                                                                style="width: 40%; text-align: right;">联系电话：</label>
                                                            <input id="infContactTel" class="easyui-validatebox textbox"
                                                                style="width: 60%" data-options="required:true">
                                                        </td>
                                                        <%--<td colspan="1" class="tdText">
                                                            <label style="width:40%;text-align:right;">报价开始时间：</label>
                                                            <input id="inqStartTime" class="easyui-datebox"
                                                                style="width: 60%">
                                                            </td>
                                                            <td colspan="1" class="tdText">
                                                                <label
                                                                    style="width:40%;text-align:right;">报价结束时间：</label>
                                                                <input id="inqEndTime" class="easyui-datebox"
                                                                    style="width: 60%">
                                                            </td>
                                                            <td colspan="1" class="tdText"><label
                                                                    style="width: 40%; text-align: right;">提交时间：</label>
                                                                <input id="inqOfrTime" class="easyui-datetimebox"
                                                                    data-options="disabled:true" style="width: 60%">
                                                            </td>--%>
                                                    </tr>
                                                    <tr style="margin-bottom: 10px">

                                                        <td colspan="1" class="tdText"><label
                                                                style="width: 40%; text-align: right;">备注：</label>
                                                            <input id="remark" class="easyui-textbox"
                                                                data-options="multiline:true"
                                                                style="width: 60%; height: 100px">
                                                        </td>
                                                        <%-- <td colspan="1" class="tdText">
                                                            <label style="width:40%;text-align:right;">创建时间：</label>
                                                            <input id="createTime" class="easyui-datebox"
                                                                style="width: 60%">
                                                            </td>
                                                            <td colspan="1" class="tdText">
                                                                <label style="width:40%;text-align:right;">创建人：</label>
                                                                <input id="createName"
                                                                    class="easyui-validatebox textbox"
                                                                    style="width: 60%">
                                                            </td>--%>
                                                    </tr>
                                                    <%-- <tr style="margin-bottom: 10px">

                                                        <td colspan="1" class="tdText">
                                                            <label style="width:40%;text-align:right;">更新人：</label>
                                                            <input id="updateName" class="easyui-validatebox textbox"
                                                                style="width: 60%">
                                                        </td>
                                                        <td colspan="1" class="tdText">
                                                            <label style="width:40%;text-align:right;">更新时间：</label>
                                                            <input id="updateTime" class="easyui-datebox"
                                                                style="width: 60%">
                                                        </td>
                                                        </tr>--%>
                                                </table>

                                            </div>
                                            <div title="物资报价明细">
                                                <table id="supplMMOfferList"></table>
                                            </div>
                                            <div title="招标文件">
                                                <table>
                                                    <!-- <tr>
                                                        <td colspan="3"><input type="button" id="uploadbtn" value="选择文件..." />
                                                            <input type="file" id="uploadpicker" accept=""
                                                                onchange="changeFile()" multiple style="display: none;" />
                                                        </td>
                                                    </tr> -->
                                                    <tr>
                                                        <td><label style="width: 40%; text-align: right;">附件下载：</label>
                                                            <ul id="checkfileList_1"></ul>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                            <!-- 物资报价列表弹窗 -->
                                            <div title="投标文件" style="padding: 5px;">
                                                <table>
                                                    <tr>
                                                        <td colspan="3"><input type="button" id="uploadbtn"
                                                                value="选择文件..." /> <input type="file" id="uploadpicker"
                                                                accept="" onchange="changeFile()" multiple
                                                                style="display: none;" />
                                                            <span>（文件名称不能包含斜杠、空格、&、#等特殊字符）</span>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td><label style="width: 40%; text-align: right;">附件下载：</label>
                                                            <ul id="checkfileList"></ul>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                    </div>

                    <script type="text/javascript">
                        var selectedFileList = [];//已选文件列表
                        var succsessCount = 0;//上传成功文件个数
                        var errorCount = 0;//上传失败文件个数
                        /************文件处理部分*************/

                        /**
                         * 保存附件
                         */

                        function saveAttch(row, obj, action) {
                            let saveNum = 0
                            if (selectedFileList.length > 0) {
                                $.each(selectedFileList, function (index, item) {
                                    showFilediv();
                                    var dataform = new FormData();
                                    dataform.append("file", item);
                                    var xmlhttp = null;
                                    if (window.XMLHttpRequest) { // code for all new browsers
                                        xmlhttp = new XMLHttpRequest();
                                    } else if (window.ActiveXObject) {// code for IE5 and IE6
                                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                                    }
                                    if (xmlhttp != null) {
                                        xmlhttp.open("POST", "api/file/springUpload?fileRow=" + row
                                            + "&fileTable=purchase_supply_compete&fileName="
                                            + item.name, true);
                                        xmlhttp.setRequestHeader('token', localStorage.getItem('tokenSupply'));
                                        xmlhttp.setRequestHeader('userType', localStorage.getItem('userType'));
                                        xmlhttp.send(dataform);
                                        xmlhttp.onreadystatechange = callbackMethods;
                                    } else {
                                        alert("你的浏览器版本不兼容，请使用更高版本的浏览器");
                                    }

                                    function callbackMethods() {
                                        if (xmlhttp.readyState == 4) {
                                            if (xmlhttp.status == 200) {
                                                saveNum += 1
                                                $.messager.show({
                                                    title: '提示',
                                                    msg: '保存成功',
                                                    timeout: 3000,
                                                    showType: 'slide'
                                                });
                                                let dg = $('#dataGridDiv');
                                                dg.datagrid('enableFilter');
                                                dg.datagrid('load');
                                                $('#supplyOfferWindow').window('close');
                                            }
                                            if (saveNum == selectedFileList.length) {
                                                hideFilediv();
                                                commitResult(obj)
                                            }
                                        } else {
                                            if (xmlhttp.status == 500) {
                                            }
                                        }
                                    }
                                });
                            } else {
                                if ('submit' == action) {
                                    commitResult(obj)
                                } else {
                                    $.messager.show({
                                        title: '提示',
                                        msg: '保存成功',
                                        timeout: 3000,
                                        showType: 'slide'
                                    });
                                    let dg = $('#dataGridDiv');
                                    dg.datagrid('enableFilter');
                                    dg.datagrid('load');
                                    $('#supplyOfferWindow').window('close');
                                }
                            }
                        }

                        /**
                         *文件框改变事件
                         */
                        function changeFile() {
                            var files = $("#uploadpicker").prop("files");
                            $.each(
                                files,
                                function (index, item) {
                                    let choiseFile = $("#checkfileList>li");
                                    if (choiseFile.length > 0) {//文件去重
                                        let count = 0;
                                        $.each(choiseFile, function (index1, item1) {
                                            if (item.name == item1.innerText) {
                                                count++;
                                            }
                                        });
                                        if (count == 0) {
                                            if (checkFileLength(item.size)) {
                                                if (item.name.includes('#') || item.name.includes('/') || item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
                                                    alert('文件名不能包含&、斜杠、反斜杠、空格等特殊字符！');
                                                    return;
                                                }
                                                $("#checkfileList")
                                                    .append(
                                                        "<li class=\"fileinfo\">"
                                                        + item.name
                                                        + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                                        + item.name
                                                        + "')\">删除</a>"
                                                        + "</li>");
                                                selectedFileList.push(item);
                                                AddMoushover();
                                            }
                                        }
                                    } else {
                                        if (checkFileLength(item.size)) {
                                            if (item.name.includes('#') || item.name.includes('/') || item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
                                                alert('文件名不能包含&、斜杠、反斜杠、空格等特殊字符！');
                                                return;
                                            }
                                            $("#checkfileList")
                                                .append(
                                                    "<li class=\"fileinfo\">"
                                                    + item.name
                                                    + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                                    + item.name
                                                    + "')\">删除</a>"
                                                    + "</li>");
                                            selectedFileList.push(item);
                                            AddMoushover();
                                        }
                                    }
                                });
                        }

                        /**
                         *    判断文件是否超过限制大小
                         * @param fileLen
                         * @returns {boolean}
                         */
                        function checkFileLength(fileLen) {
                            if (fileLen > 41943040) {
                                $.messager.alert("提示", "上传文件大小不能超过40M", "error");
                                return false;
                            }
                            return true;
                        }

                        /**
                         * //添加鼠标经过事件，鼠标划过时显示“删除”
                         * @constructor
                         */
                        function AddMoushover() {
                            $(".fileinfo").hover(function () {
                                $(this).find("a").last().css("display", "");
                            }, function () {
                                $(this).find("a").last().css("display", "none");
                            });
                        }

                        /**
                         *  移除已选择的文件
                         */

                        function RemoveFile(obj, fileId) {
                            $.messager.confirm("提示", "确认删除当前文件?", function (e) {
                                if (e) {
                                    let index = $("#checkfileList>li").index($(obj).parent());
                                    selectedFileList.splice(index, 1);
                                    $(obj).parent().remove();

                                    $.ajax({
                                        type: "post",
                                        url: 'file/deleteFile?fileId=' + fileId,
                                        success: function (data) {
                                            $.messager.alert('消息', data);
                                        },
                                        error: function (XMLHttpRequest, textStatus,
                                            errorThrown) {
                                            $.messager.alert('消息', errorThrown);
                                        }
                                    });

                                }
                            });
                        }

                        /**
                         * 取得该条数据所属的文件列表
                         * @param row
                         */
                        function getFileList(row) {
                            $.ajax({
                                type: "post",
                                url: "file/getFileList",
                                data: {
                                    fileTable: "purchase_supply_compete",
                                    fileRow: row.id
                                },
                                success: function (data) {
                                    const dataArray = eval(data);
                                    initFile(dataArray, row.status);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        /**
                         * 初始化该条数据的文件列表
                         * @param dataArray
                         */
                        function initFile(dataArray, status) {
                            $("#checkfileList").empty();
                            // 			sselectedFileNameList = [];
                            selectedFileList = [];
                            dataArray
                                .forEach(function (e, i, a) {
                                    $("#checkfileList")
                                        .append(
                                            "<li class=\"fileinfo\">"
                                            + "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('" + e.FILE_NAME + "','"
                                            + e.FILE_ID
                                            + "')\">"
                                            + e.FILE_NAME
                                            + "</a>"
                                            + (status > 0 ? '' : "<a style=\"display: none; color: red; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                                + e.FILE_ID + "')\">删除</a>")
                                            + "</li>");
                                    // 						sselectedFileNameList.push(e.FILE_NAME);
                                    if (status > 0) {

                                    } else {
                                        AddMoushover();
                                    }
                                });
                        }

                        // 文件下载
                        function downloadFile(fileName, fileRow) {
                            let url = 'api/file/download?id=' + fileRow
                            let xhr = new XMLHttpRequest()
                            xhr.open('GET', url, true)
                            xhr.setRequestHeader('token', localStorage.getItem('tokenSupply'));
                            xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                            xhr.responseType = 'blob'
                            xhr.onload = function (data) {
                                if (this.status == 200) {
                                    let blob = this.response
                                    let reader = new FileReader()
                                    reader.readAsDataURL(blob)
                                    reader.onload = function (e) {
                                        let a = document.createElement('a')
                                        a.download = fileName
                                        a.href = e.target.result
                                        $('body').append(a)
                                        a.click()
                                        $(a).remove()
                                    }
                                } else {

                                }
                            }
                            xhr.send()
                        }

                    </script>

                    <script type="text/javascript">
                        var editIndex = undefined;

                        // 行编辑结束
                        function endEditing() {
                            if (editIndex == undefined) {
                                return true
                            }
                            if ($('#supplMMOfferList').datagrid('validateRow', editIndex)) {
                                $('#supplMMOfferList').datagrid('endEdit', editIndex);
                                editIndex = undefined;
                                return true;
                            } else {
                                alert('有未填写数据!');
                                return false;
                            }
                        }

                        // 待报价物资明细列表的列
                        const notOfferedColmus = [[
                            {
                                field: 'infId',
                                title: '供应商id',
                                hidden: true,
                                formatter: function (val, rec, index) {
                                    return val ? val : '';
                                }
                            },
                            {
                                field: 'inqId',
                                title: '询价id',
                                hidden: true,
                                formatter: function (val, rec, index) {
                                    return val ? val : '';
                                }
                            },
                            {
                                field: 'mmId',
                                title: '物资id',
                                hidden: true,
                                formatter: function (val, rec, index) {
                                    return val ? val : '';
                                }
                            },
                            {
                                field: 'planId',
                                title: '采购计划_id',
                                hidden: true,
                                width: 100,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'gramId',
                                title: '采购方案ID',
                                hidden: true,
                                width: 100,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'mmUnit',
                                title: '计量单位',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'mmUnitDetail',
                                title: '计量单位描述',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'gramPurNum',
                                title: '招标数量',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'inqOfrNum',
                                title: '报价数量',
                                sortable: true,
                                width: 100,
                                editor: { type: 'numberbox', options: { required: true, precision: 3 } },
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'inqOfrUnitPrice',
                                title: '含税单价',
                                sortable: true,
                                width: 100,
                                editor: { type: 'numberbox', options: { required: true, precision: 2 } },
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'inqOfrTotalPrice',
                                title: '含税价格',
                                sortable: true,
                                width: 100,
                                // editor: {type: 'numberbox', options: {precision: 0}},
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            //         {
                            //             field: 'inqTaxRate',
                            //             title: '税率',
                            //             //  editor: {type: 'numberbox', options: {precision: 0}},
                            //             sortable: true,
                            //             formatter: function (val, rec) {
                            //                 return unescape(val ? val : '')
                            //             }
                            //         },
                            {
                                field: 'inqTaxNum',
                                title: '税码',
                                width: 150,
                                editor: {
                                    type: 'combobox',
                                    options: {
                                        url: 'sysDict/queryItemByTypeName?dicName=税码',
                                        method: 'get',
                                        valueField: "dicValue",
                                        textField: "dicName",
                                        editable: false,
                                        required: true,
                                        onSelect: function (record) {
                                        }
                                    }
                                },
                                sortable: true,
                                formatter: function (val, rec) {
                                    return rec.inqTaxRate
                                }
                            },
                            {
                                field: 'inqDeliverDate',
                                title: '交货日期',
                                sortable: true,
                                width: 150,
                                editor: { type: 'datebox' },
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            /*  {
                                  field: 'inqOfrExcludePrice',
                                  title: '不含税价格',
                                  editor: {type: 'numberbox', options: {precision: 0}},
                                  sortable: true,
                                  formatter: function (val, rec) {
                                      return unescape(val ? val : '')
                                  }
                              },*/
                            {
                                field: 'gramUseName',
                                title: '使用人姓名',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'gramUseTel',
                                title: '使用人联系方式',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },

                            {
                                field: 'createTime',
                                title: '创建时间',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            /* {
                                 field: 'updateTime',
                                 title: '更新时间',
                                 sortable: true,
                                 formatter: function (val, rec) {
                                     return unescape(val ? val : '')
                                 }
                             }*/
                            /* {
                                 field: 'status',
                                 title: '状态',
                                 sortable: true,
                                 formatter: function (val, rec) {
                                     let status = val ? val : '';
                                     return unescape(status == '0' ? '待提交' : '已提交');
                                 }
                             }*/
                        ]];

                        /**
                         * 编辑报价信息
                         */
                        function editRow() {
                            let offerRow = $('#dataGridDiv').datagrid('getSelected');
                            if (!offerRow) {
                                $.messager.alert('提示', '请选择一条数据');
                                return
                            }
                            if (+offerRow.status == 1) {
                                $.messager.alert('提示', '该报价已提交，不允许再次修改')
                                return
                            }

                            setOfferDetailWindowValue(offerRow, 'edit');
                        }

                        /**
                         * 报价详情(编辑)窗口赋值
                         */

                        function setOfferDetailWindowValue(item, action) {
                            if (item.status != 1) {
                                $('#tabs').tabs({
                                    tools: [
                                        {
                                            text: '保存',
                                            iconCls: 'icon-save',
                                            handler: function () {
                                                saveSupplyOfferMM('save');
                                            }
                                        }, {
                                            text: '提交',
                                            iconCls: 'icon-ok',
                                            handler: function () {
                                                $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                                    function (r) {
                                                        if (r) {
                                                            saveSupplyOfferMM('submit');
                                                        }
                                                    });
                                            }
                                        }]
                                })
                            } else {
                                $('#tabs').tabs({
                                    tools: []
                                });
                            }
                            $.ajax({
                                type: 'post',
                                dataType: 'json',
                                url: 'supply/compete/mm/selectList?',
                                data: { "inqId": item.inqId },
                                success: function (data) {
                                    if (data.code != 60200) {
                                        $.messager.alert('消息', data.msg);
                                    } else {
                                        $('#infId').val(item.infId)
                                        $('#inqName').val(item.inqName);
                                        $('#infContact').val(item.infContact);
                                        $('#infContactTel').val(item.infContactTel);
                                        $('#inqName').textbox({ disabled: true });
                                        $('#inqId').val(item.inqId);
                                        //  $('#inqOfrIncludePrice').numberbox('setValue', item.inqOfrIncludePrice);
                                        $('#inqOfrTime').datetimebox('setValue', item.inqOfrTime);
                                        $('#inqStartTime').datebox('setValue', item.inqStartTime);
                                        $('#inqEndTime').datebox('setValue', item.inqEndTime);
                                        $('#remark').val(item.remark);
                                        $('#createTime').datebox('setValue', item.createTime);
                                        $('#createName').val(item.createName);
                                        $('#gramDeptCode').val(item.gramDeptCode);
                                        $('#gramDeptName').val(item.gramDeptName);
                                        $('#gramGetDeptCode').val(item.gramGetDeptCode);
                                        $('#gramIsUrgent').val(item.gramIsUrgent);
                                        $('#gramFlowType').val(item.gramFlowType);
                                        $('#createTime').val(item.createTime);
                                        $('#createName').val(item.createName);
                                        //    $('#updateName').val(item.updateName);
                                        //   $('#updateTime').datebox('setValue', item.updateTime);
                                        // 构建物资报价明细的dataGrid
                                        const purchaseSupplyOfferMms = data.rows
                                        setMmsDatagird(purchaseSupplyOfferMms);
                                        getFileList(item)
                                        getFileList_1(item)

                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })
                            $('#supplyOfferWindow').window('open');
                        }

                        /**
                         *
                         */
                        function openOfferDetail(index) {
                            let dg = $('#dataGridDiv')
                            const rows = dg.datagrid('getRows')
                            let row = rows[index]
                            setOfferDetailWindowValue(row)
                        }

                        /**
                         * 提交的ajax
                         */
                        function commitResult(obj) {
                            obj.status = '1'
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'supply/compete/commit',
                                data: JSON.stringify(obj),
                                contentType: "application/json",
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    if (data.code != 60200) {
                                    } else {
                                        let dg = $('#dataGridDiv');
                                        dg.datagrid('enableFilter');
                                        dg.datagrid('load');
                                        $('#supplyOfferWindow').window('close');
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })
                        }

                        // 保存
                        function saveSupplyOfferMM(action) {
                            if (!$('#supplyOfferForm').form('validate')) {
                                alert('请先完成数据录入!');
                                return;
                            }
                            let offerStatus = '0';

                            var mainRow = $('#dataGridDiv').datagrid('getSelected');
                            // 1.首先关闭编辑器
                            $('#supplMMOfferList').datagrid('endEdit', editIndex);
                            editIndex = undefined;
                            // 2.获取物资明细
                            const supplMMOfferList = $('#supplMMOfferList').datagrid('getRows');
                            // 取得报价总数量与合计价格
                            let inqOfrNum = 0
                            let inqOfrTotalPrice = 0
                            if (supplMMOfferList != null && supplMMOfferList.length > 0) {
                                for (let i in supplMMOfferList) {
                                    // 报价数量
                                    let oferNum = supplMMOfferList[i].inqOfrNum ? Number(supplMMOfferList[i].inqOfrNum) : 0
                                    // 报价单价
                                    let oferPrice = supplMMOfferList[i].inqOfrUnitPrice ? Number(supplMMOfferList[i].inqOfrUnitPrice) : 0
                                    // 报价总数量
                                    inqOfrNum += oferNum
                                    // 物资列的含税价格重新赋值
                                    supplMMOfferList[i].inqOfrTotalPrice = oferPrice * oferNum
                                    // 合计价格
                                    inqOfrTotalPrice += oferPrice * oferNum
                                }
                            }
                            // 调用后台接口保存
                            let PurchaseSupplyOfferVO = {
                                inqEndTime: mainRow.inqEndTime,
                                inqStartTime: mainRow.inqStartTime,
                                id: mainRow.id,
                                infId: mainRow.infId,
                                infName: mainRow.infName,
                                infCode: mainRow.infCode,
                                inqId: $('#inqId').val(),
                                inqName: mainRow.inqName,
                                gramId: mainRow.gramId,
                                gramTimes: mainRow.gramTimes,
                                infContactTel: $('#infContactTel').val(),
                                infContact: $('#infContact').val(),
                                status: offerStatus,
                                // 第一次报价总额
                                inqOfrTotalPrice: inqOfrTotalPrice,
                                // 第一次报价总数量
                                inqOfrNum: inqOfrNum,
                                supplyCompeteMmModels: supplMMOfferList
                            }
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'supply/compete/save',
                                data: JSON.stringify(PurchaseSupplyOfferVO),
                                contentType: "application/json",
                                success: function (data) {
                                    //                         if (data.code != 60200) {
                                    //                             $.messager.alert('消息', data.msg);
                                    //                         } else {
                                    //                             $.messager.alert('消息', data.msg);
                                    //                             let dg = $('#dataGridDiv');
                                    //                             dg.datagrid('enableFilter');
                                    //                             dg.datagrid('load');
                                    //                             $('#supplyOfferWindow').window('close');
                                    //                         }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                },
                                complete: function (XMLHttpRequest) {
                                    console.log('XMLHttpRequest:', XMLHttpRequest)
                                    if (XMLHttpRequest.responseJSON.code != 60200) {
                                        $.messager.alert('消息', XMLHttpRequest.responseJSON.msg);
                                    } else {
                                        const result = XMLHttpRequest.responseJSON.data
                                        console.log('result:', result);
                                        // 保存附件
                                        saveAttch(result.id, PurchaseSupplyOfferVO, action)
                                        if ('save' == action) {

                                        }

                                    }
                                }
                            })
                        }

                        $('#supplyOfferWindow').window({
                            onBeforeClose: function () {
                                // onClose: function () {
                                $('#supplMMOfferList').datagrid('endEdit', editIndex);
                                editIndex = undefined;
                            }
                        })

                        // 构建物资明细dataGrid
                        function setMmsDatagird(data) {
                            let supplMMOfferList = $('#supplMMOfferList')
                            for (let item of data) {
                                item.inqOfrNum = item.inqOfrNum ? item.inqOfrNum : item.gramPurNum;
                            }

                            supplMMOfferList.datagrid({
                                //             fitColumns: true,
                                data: data,
                                iconCls: 'icon-application',
                                clientPaging: false,
                                filterDelay: 0,
                                width: 850,
                                height: 300,
                                nowrap: true,
                                rownumbers: true,
                                animate: false,
                                collapsible: false,
                                singleSelect: true,
                                frozenColumns: [
                                    [{
                                        field: 'mmCode',
                                        title: '物资编码',
                                        sortable: true,
                                        width: 120,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'mmDetail',
                                        title: '物资描述',
                                        sortable: true,
                                        width: 300,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    }
                                    ]
                                ],
                                columns: notOfferedColmus,
                                onEndEdit: onEndEdit,
                                // 行单击事件
                                onClickRow: onClickCell,
                                onLoadSuccess: function () {

                                },
                                toolbar: [{
                                    text: '一键填充',
                                    iconCls: 'icon-down',
                                    handler: function () {
                                        $.messager.confirm("提示", "确认向下复制第一行数据?", function (e) {
                                            if (e) {
                                                if (endEditing()) {
                                                    var rows = $('#supplMMOfferList').datagrid('getRows');
                                                    for (let i = 1; i < rows.length; i++) {
                                                        var row = rows[i];
                                                        // row.inqOfrNum = rows[0].inqOfrNum;
                                                        row.inqOfrUnitPrice = rows[0].inqOfrUnitPrice;
                                                        row.inqOfrTotalPrice = rows[0].inqOfrTotalPrice;
                                                        row.inqTaxRate = rows[0].inqTaxRate;
                                                        row.inqTaxNum = rows[0].inqTaxNum;
                                                        row.inqDeliverDate = rows[0].inqDeliverDate;
                                                        $('#supplMMOfferList').datagrid('updateRow', { index: i, row: row });
                                                        $('#supplMMOfferList').datagrid('refreshRow', i);
                                                    }
                                                    //                                         $('#mmOffers').datagrid('acceptChanges');
                                                    // $('#mmOffers').datagrid('reload');
                                                }
                                            }
                                        })
                                    }
                                }, '-', {
                                    text: '导出',
                                    iconCls: 'icon-export',
                                    handler: function () {
                                        exportMmList();
                                    }
                                }, '-', {
                                    text: '导入',
                                    iconCls: 'icon-up',
                                    handler: function () {
                                        $("#uploadMM").click();
                                    }
                                }
                                ],
                            });
                            supplMMOfferList.datagrid('enableFilter');
                        }

                        //导入
                        function changeMM() {
                            load();
                            let gramMmRows = $('#dataGridDiv').datagrid('getSelected');
                            var files = $("#uploadMM").prop("files");
                            var item = files[0];
                            console.log('item', item);
                            var index = item.name.lastIndexOf(".");
                            //取出从index开始到最后的字符串，赋值给extension（extension就是该文件的类型）并且转换成小写，以上文为例，取出的则是".exe",
                            var extension = item.name.substring(index).toLowerCase();
                            //这里定义允许用户上传的文件类型
                            var allowedType = [".xlsx"];
                            //判断extension是否存在于allowedType中
                            for (var i = 0; i < allowedType.length; i++) {
                                if (allowedType[i] != extension) {
                                    disLoad();
                                    alert("不支持" + extension + "格式,请上车xlsx文件");
                                    return;
                                }
                            }
                            var dataform = new FormData();
                            dataform.append("file", item);
                            var xmlhttp = null;
                            if (window.XMLHttpRequest) { // code for all new browsers
                                xmlhttp = new XMLHttpRequest();
                            } else if (window.ActiveXObject) {// code for IE5 and IE6
                                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                            }
                            if (xmlhttp != null) {
                                xmlhttp.open("POST", "api/file/springUpload?fileRow="
                                    + gramMmRows.inqId + "&fileTable=supply_offer_mm&fileName="
                                    + item.name, true);
                                xmlhttp.setRequestHeader('token', localStorage
                                    .getItem('tokenSupply'));
                                xmlhttp.setRequestHeader('userType', localStorage
                                    .getItem('userType'));
                                xmlhttp.send(dataform);
                                xmlhttp.onreadystatechange = callbackMethods;
                            } else {
                                alert("你的浏览器版本不兼容，请使用更高版本的浏览器");
                            }

                            function callbackMethods() {
                                disLoad();
                                if (xmlhttp.readyState == 4) {
                                    if (xmlhttp.status == 200) {
                                        addMMData(gramMmRows);
                                    }

                                } else {
                                    if (xmlhttp.status == 500) {
                                    }
                                }

                            }
                        }

                        function addMMData(gramMmRows) {
                            var model = {
                                fileRow: gramMmRows.inqId,
                                fileTable: 'supply_offer_mm'
                            }
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'supply/compete/importMM',
                                data: JSON.stringify(model),
                                contentType: "application/json",
                                success: function (data) {
                                    if (data.code == 60200) {
                                        editRow()
                                        $.messager.alert('消息', data.msg);
                                    } else {
                                        $.messager.alert('消息', data.msg);
                                    }
                                    $("#uploadMM").val("");
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })
                        }

                        // 导出采购计划列表
                        function exportMmList() {
                            let gramMmRows = $('#dataGridDiv').datagrid('getSelected');
                            var form = [];
                            form.push('inqId=' + gramMmRows.inqId);
                            let url = 'api/supply/compete/mm/export'
                            let xhr = new XMLHttpRequest()
                            xhr.open('POST', url, true)
                            xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                            xhr.setRequestHeader('token', localStorage.getItem('tokenSupply'));
                            xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                            xhr.responseType = 'blob'
                            xhr.onload = function () {
                                if (this.status == 200) {
                                    let blob = this.response
                                    let reader = new FileReader()
                                    reader.readAsDataURL(blob)
                                    reader.onload = function (e) {
                                        let a = document.createElement('a')
                                        a.download = '报价明细' + new Date().getTime() + '.xlsx'
                                        a.href = e.target.result
                                        $('body').append(a)
                                        a.click()
                                        $(a).remove()
                                    }
                                }
                            }
                            xhr.send(form.join('&'))
                        }

                        function onClickCell(index, field) {
                            if (editIndex != index) {
                                if (endEditing()) {
                                    $('#supplMMOfferList').datagrid('selectRow', index)
                                        .datagrid('beginEdit', index);
                                    var ed = $('#supplMMOfferList').datagrid('getEditor', { index: index, field: field });
                                    if (ed) {
                                        ($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
                                    }
                                    editIndex = index;
                                } else {
                                    setTimeout(function () {
                                        $('#supplMMOfferList').datagrid('selectRow', editIndex);
                                    }, 0);
                                }
                            }
                        }
                        function onEndEdit(index, row) {
                            var ed = $(this).datagrid('getEditor', {
                                index: index,
                                field: 'inqTaxNum'
                            });
                            row.inqTaxRate = $(ed.target).combobox('getText');
                        }
                        /**
                         *  按条件查询报价列表
                         */

                        function selectList() {
                            var startTime = $('#startTime').datebox('getValue')
                            var endTime = $('#endTime').datebox('getValue')
                            var offerStatus = $('#supplyOfferStatus').combobox('getValue');
                            var dg = $('#dataGridDiv');
                            dg.datagrid('enableFilter');
                            dg.datagrid('load', {
                                startTime: startTime ? startTime : '',
                                endTime: endTime ? endTime : '',
                                status: offerStatus ? offerStatus : ''
                            });
                        }


                        /**
                         * 构建报价列表datagrid
                         */

                        function bingGrid() {
                            let dg = $('#dataGridDiv');
                            let startTime = $('#startTime').datebox('getValue') ? $('#startTime').datebox('getValue') : ''
                            let endTime = $('#endTime').datebox('getValue') ? $('#endTime').datebox('getValue') : ''
                            let status = $('#supplyOfferStatus').combobox('getValue') ? $('#supplyOfferStatus').combobox('getValue') : ''
                            dg.datagrid({
                                title: '报价列表',
                                queryParams: {
                                    startTime: startTime,
                                    endTime: endTime,
                                    status: status
                                },
                                fitColumns: false,
                                fit: false,
                                url: 'supply/compete/selectList',
                                iconCls: 'icon-application',
                                clientPaging: false,
                                remoteFilter: true,
                                filterDelay: 0,
                                width: getWidth(0.98),
                                height: 415,
                                nowrap: true,
                                rownumbers: true,
                                animate: false,
                                collapsible: false,
                                singleSelect: true,
                                pageSize: 10,
                                remoteSort: false,
                                pagination: true,
                                frozenColumns: [[
                                    {
                                        field: 'infId',
                                        title: '供应商id',
                                        hidden: true,
                                        formatter: function (val, rec, index) {
                                            return val ? val : '';
                                        }
                                    }, {
                                        field: 'id',
                                        title: 'id',
                                        hidden: true,
                                        formatter: function (val, rec, index) {
                                            return val ? val : '';
                                        }
                                    },
                                    {
                                        field: 'inqId',
                                        title: '询价id',
                                        hidden: true,
                                        formatter: function (val, rec, index) {
                                            return val ? val : '';
                                        }
                                    },
                                    {
                                        field: 'inqName',
                                        title: '询价名称',
                                        sortable: true,
                                        formatter: function (val, rec, index) {
                                            return '<a href="javascript:void(0)" onclick="openOfferDetail(' + index +
                                                ')">' + (val ? val : '') + '</a>'
                                        }
                                    }
                                ]],
                                columns: [[
                                    {
                                        field: 'inqOfrTotalPrice',
                                        title: '合计价格',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'inqOfrNum',
                                        title: '合计数量',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'inqStartTime',
                                        title: '报价开始时间',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'inqEndTime',
                                        title: '报价结束时间',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    // {
                                    //     field: 'gramAmplitude',
                                    //     title: '单次降价幅度限制',
                                    //     sortable: true,
                                    //     formatter: function (val, rec) {
                                    //         return unescape(val ? val + '%' : '')
                                    //     }
                                    // },
                                    {
                                        field: 'gramDealMode',
                                        title: '竞价方式',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'gramTimes',
                                        title: '降价次数限制',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val == 0 ? ('无限制') : val)
                                        }
                                    },

                                    {
                                        field: 'remark',
                                        title: '备注',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'createTime',
                                        title: '创建时间',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'inqOfrTime',
                                        title: '提交时间',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    /* {
                                         field: 'updateTime',
                                         title: '更新时间',
                                         sortable: true,
                                         formatter: function (val, rec) {
                                             return unescape(val ? val : '')
                                         }
                                     },*/
                                    {
                                        field: 'status',
                                        title: '状态',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            let status = val ? val : '';
                                            return unescape(status == '0' ? '竞价中' : '已完成');
                                        }
                                    }
                                ]],
                                toolbar: [
                                    {
                                        text: '报价',
                                        iconCls: 'icon-add',
                                        handler: function () {
                                            editRow();
                                            $('#tabs').tabs('select', 0)
                                        }
                                    }, '-',
                                    // {
                                    //     text: '修改报价',
                                    //     iconCls: 'icon-edit',
                                    //     handler: function () {
                                    //         editRow();
                                    //         $('#tabs').tabs('select', 0)
                                    //     }
                                    // }, '-',
                                    {
                                        text: '报价记录',
                                        iconCls: 'icon-search',
                                        handler: function () {
                                            viewDetails();
                                        }
                                    }, '-',
                                    {
                                        text: '排名',
                                        iconCls: 'icon-favorite',
                                        handler: function () {
                                            viewRank();
                                        }
                                    }, '-',
                                    {
                                        text: '完成竞价',
                                        iconCls: 'icon-ok',
                                        handler: function () {
                                            let row = $('#dataGridDiv').datagrid('getSelected');
                                            if (row) {
                                                if (row.status == '1') {
                                                    $.messager.alert('提示', '该单据已提交！')
                                                    return
                                                }
                                                $.messager.confirm('提示', '确定要完成该报价吗?',
                                                    function (r) {
                                                        if (r) {
                                                            finishRow(row);
                                                        }
                                                    });
                                            } else {
                                                $.messager.alert('消息', '请选择要完成的报价');
                                                return
                                            }
                                        }
                                    }
                                    // , '-', {
                                    //     text: '撤回',
                                    //     iconCls: 'icon-undo',
                                    //     handler: function () {
                                    //         //撤回
                                    //         let row = $('#dataGridDiv').datagrid('getSelected');
                                    //         if (row) {
                                    //             if (row.status == '0') {
                                    //                 $.messager.alert('提示', '该单据未提交，无法撤回')
                                    //                 return
                                    //             }
                                    //             $.messager.confirm('提示', '确定要撤回该报价吗?',
                                    //                 function (r) {
                                    //                     if (r) {
                                    //                         backupOrder(row);
                                    //                     }
                                    //                 });
                                    //         } else {
                                    //             $.messager.alert('消息', '请选择要撤回的报价');
                                    //             return
                                    //         }
                                    //     }
                                    // },
                                ],
                                onLoadSuccess: function () {

                                },
                                onDblClickRow: function (rowIndex, rowData) {
                                    editRow();
                                }

                            });
                            dg.datagrid('enableFilter');
                        }

                        /**
                         *  完成
                         */
                        function finishRow(row) {
                            $.ajax({
                                type: 'post',
                                url: 'supply/compete/finish',
                                data: JSON.stringify(row),
                                contentType: "application/json",
                                dataType: 'json',
                                success: function (data) {
                                    if (data.code == 60200) {
                                        $.messager.alert('消息', data.msg)
                                        let dg = $('#dataGridDiv');
                                        dg.datagrid('enableFilter');
                                        dg.datagrid('load');
                                    } else {
                                        $.messager.alert('消息', data.msg)
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })
                        }

                        /**
                         *  撤回采购订单
                         */
                        function backupOrder(row) {
                            $.ajax({
                                type: 'get',
                                url: 'supply/compete/back?inqId=' + row.inqId + "&infId=" + row.infId,
                                // data: JSON.stringify(orderObj),
                                // contentType: "application/json",
                                dataType: 'json',
                                success: function (data) {
                                    if (data.code == 60200) {
                                        $.messager.alert('消息', data.msg)
                                        let dg = $('#dataGridDiv');
                                        dg.datagrid('enableFilter');
                                        dg.datagrid('load');
                                    } else {
                                        $.messager.alert('消息', data.msg)
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })
                        }

                        /**
                         * 取得该条数据所属的文件列表
                         * @param row
                         */
                        function getFileList_1(row) {
                            $.ajax({
                                type: "post",
                                url: "file/getFileList",
                                data: {
                                    fileTable: "purchase_inquiry",
                                    fileRow: row.inqId
                                },
                                success: function (data) {
                                    const dataArray = eval(data);
                                    initFile_1(dataArray, row.status);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        /**
                         * 初始化该条数据的文件列表
                         * @param dataArray
                         */
                        function initFile_1(dataArray) {
                            $("#checkfileList_1").empty();
                            // 			sselectedFileNameList = [];
                            selectedFileList = [];
                            dataArray
                                .forEach(function (e, i, a) {
                                    $("#checkfileList_1")
                                        .append(
                                            "<li class=\"fileinfo_1\">"
                                            + "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('" + e.FILE_NAME + "','"
                                            + e.FILE_ID
                                            + "')\">"
                                            + e.FILE_NAME
                                            + "</a>"
                                            + "</li>");
                                    // 						sselectedFileNameList.push(e.FILE_NAME);
                                    // AddMoushover_1();
                                });
                        }

                        /**
                         * //添加鼠标经过事件，鼠标划过时显示“删除”
                         * @constructor
                         */
                        function AddMoushover_1() {
                            $(".fileinfo_1").hover(function () {
                                $(this).find("a").last().css("display", "");
                            }, function () {
                                $(this).find("a").last().css("display", "none");
                            });
                        }

                        function downloadFile_1(fileName, fileRow) {
                            let url = 'api/file/download?id=' + fileRow
                            let xhr = new XMLHttpRequest()
                            xhr.open('GET', url, true)
                            xhr.setRequestHeader('token', localStorage.getItem('tokenSupply'));
                            xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                            xhr.responseType = 'blob'
                            xhr.onload = function (data) {
                                console.log('data,,,,' + data)
                                if (this.status == 200) {
                                    let blob = this.response
                                    let reader = new FileReader()
                                    reader.readAsDataURL(blob)
                                    reader.onload = function (e) {
                                        let a = document.createElement('a')
                                        a.download = fileName
                                        a.href = e.target.result
                                        $('body').append(a)
                                        a.click()
                                        $(a).remove()
                                    }
                                } else {

                                }
                            }
                            xhr.send()
                        }
                    </script>

                    <script>

                        function bingRecordGrid(row) {
                            let dg = $('#recordTT');
                            dg.datagrid({
                                title: '',
                                queryParams: {
                                    inqId: row.inqId,
                                    sort: 'inqOfrTime',
                                    order: 'desc'
                                },
                                fitColumns: false,
                                fit: false,
                                url: 'supply/compete/record/selectList',
                                iconCls: 'icon-application',
                                clientPaging: false,
                                remoteFilter: true,
                                filterDelay: 0,
                                width: 650,
                                height: 350,
                                nowrap: true,
                                rownumbers: true,
                                animate: false,
                                collapsible: false,
                                singleSelect: true,
                                pageSize: 10,
                                remoteSort: false,
                                pagination: true,
                                frozenColumns: [[
                                    {
                                        field: 'infId',
                                        title: '供应商id',
                                        hidden: true,
                                        formatter: function (val, rec, index) {
                                            return val ? val : '';
                                        }
                                    },
                                    {
                                        field: 'inqName',
                                        title: '询价名称',
                                        formatter: function (val, rec, index) {
                                            return val ? val : '';
                                        }
                                    },
                                ]],
                                columns: [[
                                    {
                                        field: 'inqOfrTotalPrice',
                                        title: '合计价格',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'inqOfrNum',
                                        title: '合计数量',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'remark',
                                        title: '备注',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'createTime',
                                        title: '创建时间',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'inqOfrTime',
                                        title: '提交时间',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'bjmx',
                                        title: '',
                                        width: 80,
                                        formatter: function (val, rec, index) {
                                            return '<a href="javascript:void(0)" onclick="openOfferMmDetail(' + index +
                                                ')">' + ('报价明细') + '</a>'
                                        }
                                    }
                                    // {
                                    //     field: 'status',
                                    //     title: '状态',
                                    //     sortable: true,
                                    //     formatter: function (val, rec) {
                                    //         let status = val ? val : '';
                                    //         return unescape(status == '0' ? '待报价' : '已报价');
                                    //     }
                                    // }
                                ]],
                                onLoadSuccess: function () {

                                },
                                onDblClickRow: function (rowIndex, rowData) {
                                    editRow();
                                }

                            });
                            dg.datagrid('enableFilter');
                        }

                        function bingRecordMmGrid(row) {
                            let dg = $('#recordMmTT');
                            dg.datagrid({
                                title: '',
                                queryParams: {
                                    inqId: row.inqId,
                                    comUuid: row.comUuid
                                },
                                fitColumns: false,
                                fit: false,
                                url: 'supply/compete/record/mm/selectList',
                                iconCls: 'icon-application',
                                clientPaging: false,
                                // remoteFilter: true,
                                filterDelay: 0,
                                width: 850,
                                height: 350,
                                nowrap: true,
                                rownumbers: true,
                                animate: false,
                                collapsible: false,
                                singleSelect: true,
                                pageSize: 10,
                                remoteSort: false,
                                pagination: true,
                                frozenColumns: [[
                                    {
                                        field: 'mmCode',
                                        title: '物资编码',
                                        width: 120,
                                        formatter: function (val, rec, index) {
                                            return val ? val : '';
                                        }
                                    },
                                    {
                                        field: 'mmDetail',
                                        title: '物资描述',
                                        formatter: function (val, rec, index) {
                                            if (val) {
                                                return '<span title="' + val + '">' + val + '</span>';
                                            } else {
                                                return val;
                                            }
                                        }
                                    },
                                ]],
                                columns: [[
                                    {
                                        field: 'mmUnit',
                                        title: '计量单位',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'mmUnitDetail',
                                        title: '计量单位描述',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'gramPurNum',
                                        title: '招标数量',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'inqOfrTotalPrice',
                                        title: '合计价格',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'inqOfrNum',
                                        title: '报价数量',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'inqOfrUnitPrice',
                                        title: '报价单价',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'inqTaxNum',
                                        title: '税码',
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'gramUseName',
                                        title: '使用人姓名',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'gramUseTel',
                                        title: '使用人联系方式',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'inqDeliverDate',
                                        title: '交货日期',
                                        sortable: true,
                                        width: 120,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'remark',
                                        title: '备注',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'inqOfrTime',
                                        title: '提交时间',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    // {
                                    //     field: 'status',
                                    //     title: '状态',
                                    //     sortable: true,
                                    //     formatter: function (val, rec) {
                                    //         let status = val ? val : '';
                                    //         return unescape(status == '0' ? '待报价' : '已报价');
                                    //     }
                                    // }
                                ]],
                                onLoadSuccess: function () {

                                },
                                onDblClickRow: function (rowIndex, rowData) {
                                }

                            });
                            // dg.datagrid('enableFilter');
                        }

                        /**
                         * 查看报价详情
                         */
                        function viewDetails() {
                            let offerRow = $('#dataGridDiv').datagrid('getSelected');
                            if (!offerRow) {
                                $.messager.alert('提示', '请选择一条数据');
                                return
                            }

                            $('#recordWindow').window('open');
                            bingRecordGrid(offerRow)
                        }

                        function openOfferMmDetail(index) {
                            let dg = $('#recordTT')
                            const rows = dg.datagrid('getRows')
                            let row = rows[index]
                            $('#recordMmWindow').window('open');
                            bingRecordMmGrid(row)
                        }
                    </script>

                    <script>
                        /**
                         * 查看报价详情
                         */
                        function viewRank() {
                            let offerRow = $('#dataGridDiv').datagrid('getSelected');
                            if (!offerRow) {
                                $.messager.alert('提示', '请选择一条数据');
                                return
                            }
                            $.ajax({
                                type: "get",
                                url: 'supply/compete/selectRank?inqId=' + offerRow.inqId,
                                success: function (data) {
                                    if (data.code == 60200) {
                                        // var rank = '当前总价排名：' + (data.data.rank ? data.data.rank + '' : '无');
                                        var rank = '';
                                        console.log('rank', rank);
                                        $('#spanRank').html(rank);
                                        $('#rankWindow').window('open');
                                        bingRankGrid(data.data.supplyCompeteMmModels)
                                    } else {
                                        $.messager.alert('消息', data.msg);
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus,
                                    errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        function updataLowStatus(index) {

                            let dg = $('#rankTT');
                            const rows = dg.datagrid('getRows')
                            let row = rows[index]
                            if (!row) {
                                $.messager.alert('提示', '请选择一条数据');
                                return
                            }
                            if (row.rank == '1') {
                                $.messager.alert('提示', '已是最低价，无需跟进！');
                                return
                            }
                            $.messager.confirm("提示", "提交后，报价会自动按照其他供应商最低价跟进，确认继续?", function (e) {
                                if (e) {
                                    $.ajax({
                                        type: "get",
                                        url: 'supply/compete/updataLowStatus?inqId=' + row.inqId + '&planId=' + row.planId,
                                        success: function (data) {
                                            if (data.code == 60200) {
                                                viewRank()
                                                $.messager.show({
                                                    title: '提示',
                                                    msg: '保存成功',
                                                    timeout: 3000,
                                                    showType: 'slide'
                                                });
                                            } else {
                                                $.messager.alert('消息', data.msg);
                                            }
                                        },
                                        error: function (XMLHttpRequest, textStatus,
                                            errorThrown) {
                                            $.messager.alert('消息', errorThrown);
                                        }
                                    });
                                }
                            })
                        }

                        function bingRankGrid(rows) {
                            let dg = $('#rankTT');
                            dg.datagrid({
                                title: '',
                                // queryParams: {
                                //     inqId: row.inqId
                                // },
                                fitColumns: false,
                                fit: false,
                                data: rows,
                                // url: 'supply/compete/selectInfo',
                                iconCls: 'icon-application',
                                clientPaging: false,
                                // remoteFilter: true,
                                filterDelay: 0,
                                width: 850,
                                height: 330,
                                nowrap: true,
                                rownumbers: true,
                                animate: false,
                                collapsible: false,
                                singleSelect: true,
                                pageSize: 10,
                                remoteSort: false,
                                pagination: true,
                                frozenColumns: [[
                                    {
                                        field: 'mmCode',
                                        title: '物资编码',
                                        width: 120,
                                        formatter: function (val, rec, index) {
                                            return val ? val : '';
                                        }
                                    },
                                    {
                                        field: 'mmDetail',
                                        title: '物资描述',
                                        formatter: function (val, rec, index) {
                                            if (val) {
                                                return '<span title="' + val + '">' + val + '</span>';
                                            } else {
                                                return val;
                                            }
                                        }
                                    },
                                    {
                                        field: 'rank',
                                        title: '单价排名',
                                        formatter: function (val, rec, index) {
                                            return val ? val : '';
                                        }
                                    },
                                ]],
                                columns: [[
                                    {
                                        field: 'mmUnit',
                                        title: '计量单位',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'mmUnitDetail',
                                        title: '计量单位描述',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'gramPurNum',
                                        title: '招标数量',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'inqOfrTotalPrice',
                                        title: '价格合计',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'inqOfrNum',
                                        title: '报价数量',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'inqOfrUnitPrice',
                                        title: '报价单价',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'inqTaxNum',
                                        title: '税码',
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : 0)
                                        }
                                    },
                                    {
                                        field: 'gramUseName',
                                        title: '使用人姓名',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'gramUseTel',
                                        title: '使用人联系方式',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'inqDeliverDate',
                                        title: '交货日期',
                                        sortable: true,
                                        width: 120,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'remark',
                                        title: '备注',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    },
                                    {
                                        field: 'inqOfrTime',
                                        title: '提交时间',
                                        sortable: true,
                                        formatter: function (val, rec) {
                                            return unescape(val ? val : '')
                                        }
                                    }, {
                                        field: 'lowStatus',
                                        title: '',
                                        width: 80,
                                        formatter: function (val, rec, index) {
                                            return '<a href="javascript:void(0)" onclick="updataLowStatus(' + index +
                                                ')">' + ('跟进最低价') + '</a>'
                                        }
                                    }
                                ]],
                                onLoadSuccess: function () {

                                },
                                onDblClickRow: function (rowIndex, rowData) {
                                }

                            });
                            // dg.datagrid('enableFilter');
                        }

                    </script>

        </body>

        </html>